<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>公司列表外部表单</title>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../common.css">
    <style>
    	
    </style>
</head>
<body >
    <div class="layui-container" id="form-page">
	    <div class="layui-row">
		    <div class="layui-col-md-offset2 layui-col-md8">
			    <div class="layui-form" id="login-form">
					<form class="layui-form" action="" method="post" enctype="multiple/form-data">
				
					</form>
				</div>
		    </div>
	    </div>
    </div>
    <script src="../../plugins/layui/layui.js"></script>
    <script src="../../plugins/vue.min.js"></script>
    <script src="../../common.js"></script>
    <script>
    	
		var vm = new Vue({
			el: "#form-page",
			data: {
				selected: '',
				paramObj: {
					files: []
				}
			},
			methods: {
				setdata (data) {
					this.paramObj = data;
					data.businessUserId == undefined ? "": this.selected = data.businessUserId;
				}
			},
			created () {
				console.log(window.paramObj)
			}
		})
    	
      	layui.use(['jquery','form','upload','ajaxmod'], function(){
			var $ = layui.jquery,
			    form = layui.form,
			    upload = layui.upload,
			    ajaxmod = layui.ajaxmod;
			
			form.on('submit(formDemo)', function(data){
				
				var formData = new FormData();
				// 文件包括表单获取
				data = {
					Name: $("input[name='Name']").val(),
					Address: $("input[name='Address']").val(),
					ContactName: $("input[name='ContactName']").val(),
					ContactMobile: $("input[name='ContactMobile']").val(),
					BusinessUserId: $("select[name='BusinessUserId']").val()
				}
				
				if ($("input[name='Id']").val() != undefined && $("input[name='Id']").val() != "") {
					data.Id = $("input[name='Id']").val()
				}
				
				$.each(data, function(name, val) {  
					formData.append(name, val);
				}); 
				 
				for (var i = 0;i<$('#inputfile')[0].files.length;i++) {
					formData.append('file', $('#inputfile')[0].files[i]);
				}
				
				var lodinggdiv = layer.msg('处理中......', {
                    zIndex: 999999999,
                    anim: 0
                    , scrollbar: false
                    , time: 0
                    , icon: 16
                    , shade: 0.5
                });
				
				$.ajax({
						url: baseUrl+'/api/sys/ent/EntCompanyAddOrUpdate?token='+cookie.get('usertoken'),
						method: 'POST',
						data: formData,
						contentType: false, // 注意这里应设为false
						processData: false,
						cache: false,
						success: function(data) {
							if(data.success){
								parent.closeandrefresh();
			                }else{
			                	layer.msg(data.message, {icon: 2});
			                }
						},
						error: function(jqXHR) {
							alert("程序异常");
							console.log(JSON.stringify(jqXHR));
						},
					})
					.done(function(data) {
						
		            })
		            .fail(function(data) {
		                console.log('fail');
		            })
		            .always(function(data) {
		            	layer.close();
		            });
				})
			    return false;
			});
    </script>
</body>
</html>